<template>
  <div class="l-rblock l-form-viewer" style="padding: 8px">
    <el-form
      :model="formData"
      :rules="rules"
      size="mini"
      labelPosition="right"
      labelWidth="100px"
      ref="form"
    >
      <div class="l-auto-window only-tabs">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane
            class="l-tabs-container"
            :label="$t('主表信息')"
            name="tab0"
          >
            <el-row :gutter="16">
              <div class="l-rblock">
                <el-col :span="24">
                  <el-form-item
                    :label="$t('供应商编号')"
                    prop="case_erp_supplier_f_Number"
                  >
                    <el-input
                      :readonly="true"
                      v-model="formData.case_erp_supplier_f_Number"
                      :placeholder="$t('please enter')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item
                    :label="$t('供应商名称')"
                    prop="case_erp_supplier_f_Name"
                  >
                    <el-input
                      :readonly="true"
                      v-model="formData.case_erp_supplier_f_Name"
                      :placeholder="$t('please enter')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item
                    :label="$t('淘汰原因')"
                    prop="case_erp_supplier_f_OutType"
                  >
                    <l-select
                      :options="case_erp_supplier_f_OutTypeOptions"
                      v-model="formData.case_erp_supplier_f_OutType"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item
                    :label="$t('淘汰说明')"
                    prop="case_erp_supplier_f_OutReason"
                  >
                    <el-input
                      type="textarea"
                      v-model="formData.case_erp_supplier_f_OutReason"
                      :placeholder="$t('please enter')"
                    />
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-form>
  </div>
</template>
<script>
const api = window.$api.erpcase.supplier;
export default {
  data() {
    return {
      moduleCode: "ERP_FormalSuppliers",
      activeName: "tab0",
      formData: {
        case_erp_supplier_f_Number: "", // 供应商编号
        case_erp_supplier_f_Name: "", // 供应商名称
        case_erp_supplier_f_OutType: "", // 淘汰原因
        case_erp_supplier_f_OutReason: "", // 淘汰说明
      },
      rules: {
        case_erp_supplier_f_Number: [{ required: true, message: "please enter" }],
        case_erp_supplier_f_Name: [{ required: true, message: "please enter" }],
        case_erp_supplier_f_OutType: [{ required: true, message: "please select" }],
        case_erp_supplier_f_OutReason: [{ required: true, message: "please enter" }],
      },
    };
  },
  computed: {
    case_erp_supplier_f_OutTypeOptions() {
      return [
        { value: "1", label: "年审不合格" },
        { value: "2", label: "其他" },
      ];
    },
  },
  methods: {
    // Reset表单
    resetForm() {
      this.$formClear(this.$refs.form);
      this.activeName = "tab0";
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }
      return true;
    },
    // 设置表单数据
    setForm(data) {
      data.f_OutType = "";
      data.f_OutReason = "";
      this.$setFormData(this.formData, data, "case_erp_supplier");
    },
    // 获取表单数据
    getForm() {
      const data = this.$getFormData(this.formData, "case_erp_supplier");
      data.f_State = 2;
      data.isOut = true;
      return data;
    },
    async loadFormData({ keyValue /*,params,node*/ }) {
      //  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
      const data = await this.$awaitWraper(api.get(keyValue));
      if (data) {
        this.setForm(data);
        return true;
      } else {
        return false;
      }
    },

    async saveForm({ keyValue /*,code,node*/ }) {
      // isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
      const postData = this.getForm();
      return await this.$awaitWraper(api.update(keyValue, postData));
    },
  },
};
</script>